const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    acceptanceList: [],
    page: 0,
    is_page: 1,
    acceptanceList: [],
    keywords: '',
    order_sn: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this,
      is_login_inspector = wx.getStorageSync('is_login_inspector');
    if (!is_login_inspector || is_login_inspector != 1) {
      wx.showToast({
        title: '请先登陆验房师账号',
        icon: 'none',
        duration: 1500
      })
      wx.switchTab({
        url: '/pages/my/my',
      })
      return false;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList();
  },
  /**
   * @xk 获取待受理 预约订单
   * @param {*} obj 
   */
  getList: function (obj) {
    var that = this,
      page = this.data.page,
      keywords = this.data.keywords,
      is_page = this.data.is_page,
      acceptanceList = this.data.acceptanceList;
    https.post('getWaitSureBookOrder', {
      page: page,
      is_page: is_page,
      keywords: keywords
    }, false, '正在加载').then(res => {
      if (res.list) {
        acceptanceList.push.apply(acceptanceList, res.list);
        that.setData({
          acceptanceList: acceptanceList,
          page: res.page
        })
      }
    })
  },
  /**
   * 弹出受理订单
   * @param {}} e 
   */
  acceptanceTap(e) {
    var order_sn = e.currentTarget.dataset.order_sn;
    if (order_sn) {
      this.setData({
        order_sn: order_sn,
        maskActive: true
      })
    }
  },
  makeSure: function (res) {
    var that = this,
      inspector_id = wx.getStorageSync('inspector_id'),
      order_sn = this.data.order_sn;
    https.post('makeSureBookOrder', {
      order_sn: order_sn,
      inspector_id: inspector_id
    }, false, '正在受理').then(res => {
      if (res) {
        setTimeout(() => {
          wx.navigateTo({
            url: '/pages/acceptance_tip/acceptance_tip?order_sn='+order_sn,
          })
        }, 1000);
      }
    })
  },
  qxmasktap() {
    this.setData({
      maskActive: false
    })
  },
  chanageNum: function(obj){
    //切换账号
    wx.removeStorageSync('is_login_inspector');
    wx.removeStorageSync('inspector_id');
    wx.navigateBack({
      delta: 0,
    })
  },
  chanagekeywords: function(obj){
    this.setData({
      keywords: obj.detail.value
    })
  },
  search: function(obj){
    var keywords = this.data.keywords;
    if(keywords != ''){
      this.setData({
        page: 0,
        is_page: 1,
        acceptanceList: []
      })
      this.getList();
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      keywords: '',
      page: 0,
      is_page: 1,
      acceptanceList: []
    })
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList();
  },

})